package com.xueyi.aixihu.mapper;

import com.xueyi.aixihu.entity.po.AxhFinance;
import com.xueyi.aixihu.entity.po.AxhFinanceLog;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;


/**
 * 描述: 操作表信息
 *
 * @author 刘梓江
 * @date 2023/3/23 09:45
 */
public interface OperationFinanceMapper {


    /**
     * 查询指定年下到报表信息
     *
     * @param
     * @return
     */
    @Select({
            "<script>",
            " select * from axh_finance where ",
            "<if test='type==1'>",
                "DATE_FORMAT(create_time,'%Y')=#{date} ",
            "</if >",
            "<if test='type==2'>",
                "DATE_FORMAT(create_time,'%Y-%m')=#{date} ",
            "</if >",

            "</script>",
    })
    List<AxhFinance> selectFinanceByYearOrMonth(Integer type, String date);

    /**
     * 查询指定报表日志信息
     *
     * @param financeIds
     * @return
     */
    @Select({
            "<script> ",
            "select * from axh_finance_log where finance_id  in ",
            "(",
            "<foreach collection ='financeIds' item ='item' index = 'index' separator=','> ",
            "#{item}",
            "</foreach>",
            ")",
            "</script> ",
    })
    List<AxhFinanceLog> selectFinanceLogBytFinanceId(@Param("financeIds") List<Integer> financeIds);


    /**
     * 批量修改报表日志
     *
     * @param financeLogs
     */
    @Update
            ({
                    "<script> ",
                    " UPDATE  axh_finance_log",
                    " <trim prefix ='set' prefixOverrides=',' > ",
                    "<trim prefix ='create_time = case' suffix='end'>",
                    "<foreach collection ='financeLogs' item ='item' index = 'index'> ",
                    "when id = #{item.id} then #{item.createTime} ",
                    "</foreach>",
                    "</trim> ",
                    " </trim> ",
                    " WHERE id in ",
                    " (",
                    "<foreach collection='financeLogs' item='item' index='index' separator=','>",
                    " #{item.id}",
                    "</foreach>",
                    " )",
                    "</script>"
            })
    void batchUpdateFinanceLog(@Param("financeLogs") List<AxhFinanceLog> financeLogs);

}
